package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AppRoomImg;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 房间背景
 */
@Repository
public class AppRoomImgDao extends BaseDao<AppRoomImg> {

    /**
     * 查询列表
     */
    public List<AppRoomImg> OfficialPersonalList(Integer userid) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_img where 1=1  ");
        sbStr.append(" and leixing = 1 or ( ");
        sbStr.append(" leixing = 2 ");
        sbStr.append(" and userid = ? )");
        paramList.add(userid);
        sbStr.append(" order by leixing desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppRoomImg.class,null);
    }


    /**
     * 详情
     */
    public AppRoomImg get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_img where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomImg.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppRoomImg haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_room_img where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 根据用户id获取内容
     */
    public AppRoomImg getUser(Integer userid) {
        if (StringEx.isNullOrLing(userid)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_img where 1=1");
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomImg.class);
    }

    /***
    * 修改背景图
    * @Param: [id, img]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/5
    * @Time: 17:31
    */
    public void saveImg(Integer id,String img){
        if(StringEx.isNullOrLing(id)){
            return;
        }
        if(StringEx.isNull(img)){
            return;
        }
        List<Object> paramList = new ArrayList<Object>();
        String sql = " UPDATE app_room_img SET url  = ? WHERE id = ? ";
        paramList.add(img);
        paramList.add(id);
        this.update(sql,paramList);
    }

}
